{% extends 'base_foot.html' %}
{#模板继承于base_foot#}

{% block head %}
    <script type="text/javascript" src="/static/js/register.js"></script>
    <script type="text/javascript">
	$(function(){

	var error_name = false;
	var error_email = false;
	var error_check = false;


	$('#user_name').blur(function() {
		check_user_name();
	});

	$('#email').blur(function() {
		check_email();
	});

	$('#allow').click(function() {
		if($(this).is(':checked'))
		{
			error_check = false;
			$(this).siblings('span').hide();
		}
		else
		{
			error_check = true;
			$(this).siblings('span').html('请勾选同意');
			$(this).siblings('span').show();
		}
	});


	function check_user_name(){
		var len = $('#user_name').val().length;

		if(len<5||len>20)
		{
			$('#user_name').next().html('输入5-20个字符的用户名');
			$('#user_name').next().show();
			error_name = true;

		}
		else
		{
			$.get('{% url "df_user:register_exist" %}?uname='+$('#user_name').val(),function(data){
                if (data.count >= 1) {
                    $('#user_name').next().hide();
                    error_name = false;
                }else{
                    $('#user_name').next().html('用户名不存在').show();
                    error_name = true;
                }
            });
        }
	}


	function check_email(){
		var re = /^[a-z0-9][\w\.\-]*@[a-z0-9\-]+(\.[a-z]{2,5}){1,2}$/;
		if(!re.test($('#email').val()))
		{
		    $('#email').next().html('你输入的邮箱格式不正确');
			$('#email').next().show();
			error_email = true;
		}
		else
		{
			$.get('{% url "df_user:register_exist" %}?uemail='+$('#email').val(),function(data){
                if (data.email_count >= 1) {
                    $('#email').next().hide();
                    error_email = false;
                }else{
                    $('#email').next().html('邮箱尚未注册').show();
                    error_email = true;
                }
            });
		}

	}


	$('#reg_form').submit(function() {
		check_user_name();
		check_email();

		if(error_name == false && error_email == false && error_check == false)
		{
			return true;
		}
		else
		{
			return false;
		}

	});
});
    </script>
{% endblock head %}

{% block body %}
	<div class="register_con">
		<div class="l_con fl">
			<a class="reg_logo"><img src="/static/images/logo_banner2.png" style="width: 300px;height:100px;overflow: hidden;object-fit: cover;"></a>
			<div class="reg_slogan">跳蚤虽小五脏全，东西南北货物多</div>
			<div class="reg_banner"><img src="/static/images/register_banner.jpg" style="width: 250px;height:330px;overflow: hidden;object-fit: cover;margin-right: 20px;"></div>
		</div>

		<div class="r_con fr">
			<div class="reg_title clearfix">
				<h1>重置密码</h1>
				<a href="{% url "df_user:login" %}">登录</a>
			</div>
			<div class="reg_form clearfix">
				<form action="{% url "df_user:findpwdView" %}" id='reg_form' method="post">
                    {% csrf_token %}
				<ul>
                    <li>
                        <label>用户名:</label>
                        <input type="text" name="username" id="username">
                        <span class="error_tip">提示信息</span>
                    </li>
                    <li>
						<label>邮箱:</label>
						<input type="text" name="email" id="email">
						<span class="error_tip">提示信息</span>
					</li>
					<li class="agreement">
						<input type="checkbox" name="allow" id="allow" checked="checked">
						<label>同意《跳蚤市场使用协议》</label>
						<span class="error_tip2">提示信息</span>
					</li>
					<li class="reg_sub">
						<input type="submit" value="重置密码">
					</li>
				</ul>				
				</form>

			</div>

		</div>

	</div>
{#  弹窗提示  #}
    {% if messages %}
    <script>
        {% for msg in messages %}
            alert('{{ msg.message }}');
        {% endfor %}
    </script>
    {% endif %}
{% endblock body %}